package com.itheima.exhandler;

import com.itheima.domin.vo.Result;
import com.itheima.exception.ClientException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**全局异常处理器
 * @Author:上官徵羽
 * @Date: 2025/07/14 15:58
 * @Description TODO 今日内容:
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 常态异常
     * @param e
     * @return
     */
    //@ExceptionHandler
    public Result handleException(Exception e){
        log.error("{}",e.getMessage());
        return Result.error("服务器正忙,请稍后重试");
    }

    /**
     * 自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler
    public Result handleClientException(ClientException e){
        log.error("{}",e.getMessage());
        return Result.error(e.getMessage());
    }
}
